﻿$(document).ready(function() {
    //ShowType();
    ListByType();
    document.getElementById("iEstateName").value = "";
    document.getElementById("roomNo").value = "";
});

function ListByType() {
    var type = "是否开启房号验证";
    $.ajax({
        type: 'POST',
        url: '../Handler/HandlerHousing.ashx',
        data: 'act=GetOption&type=' + type,
        timeout: '10000',
        error: function() {
            alert("系统繁忙，请稍候后试！");
        },
        success: function(json) {
            ListByTypeCallBack(json);
        }
    });
}

function ListByTypeCallBack(response) {

    if (response == null || response.length == 0) return;
    if (response == 0) {
        document.getElementById("roomNo").readOnly = true;
        document.getElementById("floor").readOnly = true;
    }

}

var checkSubmitFlg = false;

//提交
function submitOk() {


   

    var usestr = document.getElementById("use").value;
    if (usestr == "请选择") {
        alert("请选择用途！");
        return false;
    }

    var bname1 = document.getElementById("iEstateName").value;
    if (bname1 == "") {
        alert("请输入楼盘名称!");
        return false;
    }
    var bname = LexunJS.GetSelectText("buildName1");
    if (bname == "请选择") {
        alert("请选择栋阁！");
        return false;
    } else {
        if (bname.length = 0 || bname.replace(/(^\s*)|(\s*$)/g, "") == "") {
            alert("请选择栋阁！");
            return false;
        }
    }
    var roomno = document.getElementById("roomNo").value;
    if (roomno == "") {
        alert("请输入房间号！");
        return false;
    }

    var floor = document.getElementById("floor").value;
    //商铺可以录入负数层
    if (usestr == "2") {
        if (/^(\+|-)?\d+($|\.\d+$)/.test(floor)) {
           
        }
        else {
            alert("请输入正数或者负数！");
            return false;
        }

    } else {
        if (!LexunJS.isValidPositiveInteger(floor)) {
            alert("楼层只能为数字！");
            return false;
        }
    }
    var owner = document.getElementById("owner").value;
    if (owner.length = 0 || owner.replace(/(^\s*)|(\s*$)/g, "") == "") {
        alert("请输入业主名称！");
        return false;
    }
    var ownerTel = document.getElementById("ownerTel").value;
    if (ownerTel.length = 0 || ownerTel.replace(/(^\s*)|(\s*$)/g, "") == "") {
        alert("请输入业主电话！");
        return false;
    }
    var p1 = /^((1[0-9]{1}[0-9]{1})+\d{8})|(^(0[0-9]{2,3}\-)?([2-9][0-9]{6,7})+(\-[0-9]{1,4})?$)|(^([0-9]{3,5}\-)?([0-9]{3,8})?(\-[0-9]{3,8}))$/;
    if (ownerTel.substr(0, 1) == "1") {
        if (ownerTel.length != "11") {
            alert("号码格式不正确，请检查输入的电话号码");
            return false;
        }
    }
    if (p1.test(ownerTel) == false && ownerTel != "") {
        alert("号码格式不正确，请检查输入的电话号码");
        return false;
    }
    var linkmanTel = document.getElementById("linkmanTel");
    if (linkmanTel.value.substr(0, 1) == "1") {
        if (linkmanTel.value.length != "11") {
            alert("号码格式不正确，请检查输入的电话号码");
            return false;
        }
    }
    if (p1.test(linkmanTel.value) == false && linkmanTel.value != "") {
        alert("号码格式不正确，请检查输入的电话号码");
        return false;
    }
    var acreage = document.getElementById("acreage").value;
    if (acreage.length = 0 || acreage.replace(/(^\s*)|(\s*$)/g, "") == "") {
        alert("请输入面积！");
        return false;
    }
   
    var tradeType = document.getElementById("tradeType").value;
    if (tradeType == "") {
        alert("请选择交易！");
        return false;
    }

    if (tradeType == "1") {
        var SalePrice = document.getElementById("totalprice").value;
        if (SalePrice == "") {
            alert("请输入售价！");
            return false;
        }

    }

    if (tradeType == "2") {
        var LeasePrice = document.getElementById("leaseprice").value;
        if (LeasePrice == "") {
            alert("请输入租金！");
            return false;
        }

    }
    if (usestr == "1") {
        var room = LexunJS.GetSelectText("room");
        if (room == "请选择") {
            alert("请选择户型！");
            return false;
        }

        var age = document.getElementById("age").value;
        if (age == "" || age == "0") {
            alert("选输入房龄！");
            return false;
        }
        if (tradeType == "2") {
            var rentNumber = document.getElementById("rentNumber").value;
            if (rentNumber == "") {
                alert("请输入几租！");
                return false;
            }

            var depositNumber = document.getElementById("depositNumber").value;
            if (depositNumber == "") {
                alert("请输入几押！");
                return false;
            }
        }
        var trueArea = document.getElementById("trueArea").value;
        if (trueArea.length = 0 || trueArea.replace(/(^\s*)|(\s*$)/g, "") == "") {
            alert("请填写使用面积！");
            return false;
        }
    }
    
    var status = document.getElementById("status").value;
    if (status == "") {
        alert("请选择状态！");
        return false;
    }

    //判断是否是赎楼 1,代表是
    if (document.getElementById("redeem").checked) {
        document.getElementById("redeem1").value = "1";
    } else {
        document.getElementById("redeem1").value = "0";
    }
    //判断是否有钥匙 1,代表选是   
    if (document.getElementById("hasKey").checked) {
        document.getElementById("hasKey1").value = "1";
        var keyno = document.getElementById("keyNo").value;
        if (keyno.length = 0 || keyno.replace(/(^\s*)|(\s*$)/g, "") == "") {
            alert("钥匙编号不能为空！");
            return false;
        }
        var keepKey = document.getElementById("keepKey").value;
        if (keepKey.length = 0 || keepKey.replace(/(^\s*)|(\s*$)/g, "") == "") {
            alert("钥匙人员不能为空！");
            return false;
        } else if (keepKey.indexOf('[') == -1 && keepKey.indexOf('*') == -1) {
            alert('钥匙人员格式错误,如：张三[00001,xxx组]');
            document.getElementById('keepKey').focus();
            return false
       
        }
        var keepKeyDate = document.getElementById("keepKeyDate").value;
        if (keepKeyDate.length = 0 || keepKeyDate.replace(/(^\s*)|(\s*$)/g, "") == "") {
            alert("收钥匙时间不能为空！");
            return false;
        }
    } else {
        document.getElementById("hasKey1").value = "0";
    }
    //判断是否是独家 1,代表选中
    if (document.getElementById("isOnly").checked) {
        document.getElementById("isonly1").value = "1";
        var OnlyUser = document.getElementById("OnlyUser").value;
        if (OnlyUser.length = 0 || OnlyUser.replace(/(^\s*)|(\s*$)/g, "") == "") {
            alert("独家人员不能为空！");
            return false;
        } else if (OnlyUser.indexOf('[') == -1 && OnlyUser.indexOf('*') == -1) {
            alert('独家人员格式错误,如：张三[00001,xxx组]');
            document.getElementById('OnlyUser').focus();
            return false
       
        }
        var OnlyDate = document.getElementById("OnlyDate").value;
        if (OnlyDate.length = 0 || OnlyDate.replace(/(^\s*)|(\s*$)/g, "") == "") {
            alert("独家时间不能为空！");
            return false;
        }
    } else {
        document.getElementById("isonly1").value = "0";
    }
    //判断是否是反签
    if (document.getElementById("ctyCont").checked) {
        document.getElementById("ctyCont1").value = "1";
        var ctyContUser = document.getElementById("ctyContUser").value;
        if (ctyContUser.length = 0 || ctyContUser.replace(/(^\s*)|(\s*$)/g, "") == "") {
            alert("反签人员不能为空！");
            return false;
        } else if (ctyContUser.indexOf('[') == -1 && ctyContUser.indexOf('*') == -1) {
            alert('反签人员格式错误,如：张三[00001,xxx组]');
            document.getElementById('ctyContUser').focus();
            return false
       
        }
        var ctyContDate = document.getElementById("ctyContDate").value;
        if (ctyContDate.length = 0 || ctyContDate.replace(/(^\s*)|(\s*$)/g, "") == "") {
            alert("反签时间不能为空！");
            return false;
        }
    } else {
        document.getElementById("ctyCont1").value = "0";
    }
    //获取房屋设施选中的值
    var arrInputControls;
    arrInputControls = document.getElementsByName("hAppliances");
    var hAppliances = "";
    for (i = 0; i < arrInputControls.length; i++) {
        if (arrInputControls[i].checked == false) {
            hAppliances += "0" + ",";
        } else {
            hAppliances += "1" + ",";
        }
    }
    if (hAppliances != "") {
        hAppliances = hAppliances.substr(0, hAppliances.length - 1);
    }
    document.getElementById("hAppliances1").value = hAppliances;

    //ZLHOME 对接，扩展字段
    if (document.getElementById("whetherLease").checked) {
        document.getElementById("whetherLease1").value = 1;
    }

    if (document.getElementById("inLease").checked) {
        document.getElementById("inLease1").value = 1;
    }

    if (document.getElementById("settle").checked) {
        document.getElementById("settle1").value = 1;
    }

    if (document.getElementById("degree").checked) {
        document.getElementById("degree1").value = 1;
    }
    
    

    if (!checkSubmitFlg) {

        // 第一次提交
        checkSubmitFlg = true;
    } else {

        //重复提交
        alert("按一次就够了，请勿重复提交！请耐心等待！谢谢合作！");
        return false;
    }


    //提交信息
    document.forms[0].submit();
}

//加载房屋设施列表
function ShowType() {
    var type = "房屋设施";
    $.ajax({
        type: 'POST',
        url: '../Handler/HandlerHousing.ashx',
        data: 'act=ListByType&type=' + type,
        timeout: '10000',
        error: function() {
            alert("编缉失败！");
        },
        success: function(json) {
            showDetailCallBack(json);
        }
    });
}

function showDetailCallBack(response) {
    var json = eval("(" + response + ")");
    var record = json.record;
    if (record == null || record.length == 0) return;
    var recordLength = record.length;
    var arr = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;房屋设施";
    for (var i = 0; i < recordLength; i++) {
        if (i % 8 == 0 && i > 0) {
            arr += "<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
        }
        arr += "<input id='hAppliances' name='hAppliances' type='checkbox' />" + record[i].item + "";
    }

    document.getElementById("divhAppliances").innerHTML = arr + "<input id='btnCheck' class='button_bak' type='button' value='反选' onclick='SelectAll()' />";
}

//checkbox全选反选
function SelectAll() {
    var arrInputControls;
    arrInputControls = document.getElementsByName("hAppliances");
    if (arrInputControls == null) {
        return;
    }
    for (i = 0; i < arrInputControls.length; i++) {
        if (arrInputControls[i].checked == false) {
            arrInputControls[i].checked = true;
        } else {
            arrInputControls[i].checked = false;
        }

    }
}
//全选
function SelectAll1() {
    var arrInputControls;
    arrInputControls = document.getElementsByName("hAppliances");
    if (arrInputControls == null) {
        return;
    }
    for (i = 0; i < arrInputControls.length; i++) {
        arrInputControls[i].checked = true;

    }

}

function loadparentBuild() {
    var id = LexunJS.GetSelectValue("buildName1");
    document.getElementById("bid1").value = id; //栋阁id，名称
    document.getElementById("bname1").value = LexunJS.GetSelectText("buildName1");
//    if (LexunJS.GetSelectText("buildName1") == "请选择") {
//        var obj = document.getElementById("buildName2");
//        obj.options.length = 0;
//        document.getElementById("bname2").value = "";
//        LexunJS.selectAddOption(obj, "请选择", 0);

//        
//        var obj1 = document.getElementById("buildName3");
//        obj1.options.length = 0;
//        document.getElementById("bname3").value = "";
//        LexunJS.selectAddOption(obj1, "请选择", 0);
//       

//        return;        
//     }
    $.ajax({
        type: 'POST',
        url: '../Handler/HandlerIndex.ashx',
        data: 'act=SelectNamesByBId&id=' + id,
        timeout: '10000',
        error: function() {
            alert("系统繁忙，请稍候后试！");
        },
        success: function(json) {
            SelectNameByParent(json);
        }
    });
}

// 加载城市列表回调
function SelectNameByParent(response) {
    var json = eval("(" + response + ")");
    var record = json.record;

    document.getElementById("buildName2").options.length = 0;
    document.getElementById("buildName3").options.length = 0;

    $("#buildName2").html("");
    $("#bid2").html("");
    
    var obj = document.getElementById("buildName2");

    LexunJS.selectAddOption(obj, "请选择", 0);
    
    if (record == null || record.length == 0) return;
//    
//    if (record == null || record.length == 0){
//        document.getElementById("buildName2").style.display = "none";
//        document.getElementById("buildName3").style.display = "none";
//       
//    }else{
//        document.getElementById("buildName2").style.display = "";
    //    }
    

    var recordLength = record.length;
    for (var i = 0; i < recordLength; i++) {
        var sName = record[i].name;
        var sValue = record[i].id;

        LexunJS.selectAddOption(obj, sName, sValue);
    }
}

function loadparentBuild3() {
    var id = LexunJS.GetSelectValue("buildName2");
    document.getElementById("bid2").value = id; //栋阁id，名称
    document.getElementById("bname2").value = LexunJS.GetSelectText("buildName2");
   
//    if (LexunJS.GetSelectText("buildName2") == "请选择") {
//    
//        var obj = document.getElementById("buildName3");
//        obj.options.length = 0;
//        document.getElementById("bname3").value = "";
//        LexunJS.selectAddOption(obj, "请选择", 0);
//        return;
//       
//    }

    $.ajax({
        type: 'POST',
        url: '../Handler/HandlerIndex.ashx',
        data: 'act=SelectNamesByBId&id=' + id,
        timeout: '10000',
        error: function() {
            alert("编缉失败！");
        },
        success: function(json) {
            SelectNameByParent3(json);
        }
    });
}

// 加载城市列表回调
function SelectNameByParent3(response) {
    var json = eval("(" + response + ")");
    var record = json.record;

    document.getElementById("buildName3").options.length = 0;

    $("#buildName3").html("");
    $("#bid3").html("");

    var obj = document.getElementById("buildName3");

    LexunJS.selectAddOption(obj, "请选择", 0);

    if (record == null || record.length == 0) return;
//    if (record == null || record.length == 0) {
//        document.getElementById("buildName3").style.display = "none";
//        return;
//    }
//    else {
//        document.getElementById("buildName3").style.display = "";
//       
//    }
    var recordLength = record.length;
    for (var i = 0; i < recordLength; i++) {
        var sName = record[i].name;
        var sValue = record[i].id;

        LexunJS.selectAddOption(obj, sName, sValue);
    }
}

function loadparentBuildName() {
    document.getElementById("bid3").value = LexunJS.GetSelectValue("buildName3"); //栋阁id，名称
    document.getElementById("bname3").value = LexunJS.GetSelectText("buildName3");
}

function DisplyDiv() {
    var usage = LexunJS.GetSelectValue("use");
    if (usage == "2") {
        document.getElementById("divprice").style.display = "";
        document.getElementById("divzk").style.display = "";
        document.getElementById("houseStyle").style.display = "none";
        document.getElementById("divFitment").style.display = "none";
        document.getElementById("divStyle").style.display = "none";

    } else {
        document.getElementById("divprice").style.display = "none";
        document.getElementById("divzk").style.display = "none";
        document.getElementById("divFitment").style.display = "";
        document.getElementById("divStyle").style.display = "";
    }
    
}

//弹出窗口,取返回值
function roomNoDialog() {
  
    var ename = document.getElementById("iEstateName").value;
    var bname2 = document.getElementById("bname2").value;
    var bname3 = document.getElementById("bname3").value;
    var id = document.getElementById("buildName1").value;
    if (bname2.length > 0) {
        id = document.getElementById("buildName2").value;
    }
    if (bname3.length > 0) {
        id = document.getElementById("buildName3").value;
    }

    if (id == 0 || id == "") {
        alert("请选择栋阁！");
        return;
    }

    //弹出房号列表
    var path = "../TM/ShowChangeRooms.aspx?id=" + id;
    var parameter = "";
    var style = "dialogWidth:638px; dialogHeight:563px; status:0;scroll:1; help:0; resizable:1;Scrollbars=yes,Toolbar=no,Location=no,Direction=no,Resizeable=no";
    var arrStr = window.showModalDialog(path, parameter, style);   // arrStr返回值为两类 1直接返回盘源ID  2房号,房号ID,楼层,交易类型
    if (typeof (arrStr) == "undefined" || arrStr == null) {
        return;
    }
    // -1表示不存在分号
    if (arrStr.indexOf(',') == -1) {
        if (parseInt(arrStr) <= 0)
            return;

        $.ajax({
            type: 'POST',
            url: '../Handler/HandlerHousing.ashx',           
            data: 'act=SelectHousig&id=' + arrStr,
            timeout: '10000',
            error: function() {
                alert("加载失败！");
            },
            success: function(json) {
                showDetailCallBack(json);
            }
        });
    } else {
        if (typeof (arrStr) == "undefined" || arrStr == null) {
            return;
        }

        var str = new Array();
        str = arrStr.split(',');

        document.getElementById("roomNo").value = "";
        document.getElementById("roomid").value = "";
        document.getElementById("floor").value = "";
        document.getElementById("tradeType").value = 0;

        document.getElementById("roomNo").value = str[0];
        document.getElementById("roomid").value = str[1];
        document.getElementById("floor").value = str[2];
        document.getElementById("tradeType").value = str[3];
    }
}

function showDetailCallBack(response) {

    var json = eval("(" + response + ")");
    var record = json.record;

    if (record == null || record.length == 0) 
        return;

    var recordLength = record.length;
    for (var i = 0; i < recordLength; i++) {

        var userid = document.getElementById("userid").value;
        var deptid = document.getElementById("deptid").value;
        var updateid = document.getElementById("updateId").value; //修改本部客源
        var mid = document.getElementById("mid").value; //修改全部客源

        var usage = record[i].use;

        if (usage == "2") {
            document.getElementById("divprice").style.display = "";
            document.getElementById("divzk").style.display = "";
        } else {
            document.getElementById("divprice").style.display = "none";
            document.getElementById("divzk").style.display = "none";

        }
        if (usage != "1") {
            document.getElementById("divhAppliances").style.display = "none";
            document.getElementById("huxing").style.display = "none";
        }
        document.getElementById("use").value = record[i].use;
        //LexunJS.selectAddOption(use, record[i].use, record[i].use);
        //alert(record[i].use);

        var buildName1 = document.getElementById("buildName1");
        var buildName2 = document.getElementById("buildName2");
        var buildName3 = document.getElementById("buildName3");
        
        document.getElementById("iEstateName").value = record[i].ename;        
        if (record[i].buildname1 != "" && typeof (record[i].buildname1) != "undefined" && typeof (record[i].buildname2) != "undefined" && record[i].buildname2 != "" && record[i].bulidname3 != "" && typeof (record[i].bulidname3) != "undefined") {
            LexunJS.selectAddOption(buildName1, record[i].bulidname3, record[i].buildid3);
            LexunJS.selectAddOption(buildName2, record[i].buildname1, record[i].buildid1);
            LexunJS.selectAddOption(buildName3, record[i].buildname2, record[i].buildid2);
        } else if (record[i].buildname1 != "" && typeof (record[i].buildname1) != "undefined" && typeof (record[i].buildname2) != "undefined" && record[i].buildname2 != "") {
            LexunJS.selectAddOption(buildName1, record[i].buildname1, record[i].buildid1);
            LexunJS.selectAddOption(buildName2, record[i].buildname2, record[i].buildid2);
        } else if (record[i].buildname2 != "" && typeof (record[i].buildname2) != "undefined") {
            LexunJS.selectAddOption(buildName1, record[i].buildname2, record[i].buildid2);
        }

        document.getElementById("bname1").value = record[i].buildname;
        document.getElementById("roomid").value = record[i].roomid;
        document.getElementById("roomNo").value = record[i].roomno;
        document.getElementById("dname1").value = record[i].dname;
        document.getElementById("area1").value = record[i].area;
        var dname = document.getElementById("dname");
        LexunJS.selectAddOption(dname, record[i].dname, record[i].did);
        var area = document.getElementById("area");
        LexunJS.selectAddOption(area, record[i].area, record[i].aid);

        document.getElementById("tenant").value = record[i].tenant; //租客
        document.getElementById("assignmentfee").value = record[i].assignmentfee; //转让费
        //document.getElementById("markUId1").value = record[i].markuid; //登盘人ID
        //document.getElementById("markUser1").value = record[i].markuser; //登盘人名称
        //document.getElementById("markUDeptId1").value = record[i].markudeptid;
        //document.getElementById("markUDept1").value = record[i].markudept;
        document.getElementById("addUId1").value = record[i].adduid;
        document.getElementById("addUser1").value = record[i].adduser;
        document.getElementById("addUDept1").value = record[i].addudept;
        document.getElementById("addUDeptId1").value = record[i].addudeptid;
        document.getElementById("addUBankId1").value = record[i].addubank;
        document.getElementById("acreage").value = record[i].acreage;

        var tradeType = document.getElementById("tradeType"); //类型
        tradeType.selectedIndex = record[i].tradetype
        if (tradeType.value == "1") {
            document.getElementById("sprice1").value = "万";
            document.getElementById("sprice").value = "万";
            document.getElementById("divleaseprice").style.display = "none";
            document.getElementById("divleaseYear").style.display = "none";
            document.getElementById("divtotalprice").style.display = "";
        } else {
            document.getElementById("sprice1").value = "元";
            document.getElementById("sprice").value = "元";
            document.getElementById("divleaseYear").style.display = "";
            document.getElementById("divleaseprice").style.display = "";
            document.getElementById("divtotalprice").style.display = "none";
        }
        document.getElementById("linkman").value = record[i].linkman;

        var status = document.getElementById("status"); //状态
        status.selectedIndex = 0;
       
        document.getElementById("totalprice").value = record[i].totalprice; //总价
        document.getElementById("unitprice").value = record[i].unitprice;
        document.getElementById("costprice").value = record[i].costprice;
        document.getElementById("leaseprice").value = record[i].leaseprice;

        var source = document.getElementById("source");
        LexunJS.selectAddOption(source, record[i].source, record[i].source);

        document.getElementById("pocNo").value = record[i].pocno;

        document.getElementById("houseType").value = record[i].housetype;
        document.getElementById("keyNo").value = record[i].keyno;
        if (record[i].haskey == "1") {//是否有钥匙1.有
            document.getElementById("hasKey").checked = true;
        }
        if (record[i].isonly == "1") {//是否钥匙1.有
            document.getElementById("isOnly").checked = true;
        }
        if (record[i].ctycont == "1") {//反签1.是
            document.getElementById("ctyCont").checked = true;
        }
        if (record[i].redeem == "1") {//赎楼.1是
            document.getElementById("redeem").checked = true;
        }
        document.getElementById("keepKey").value = record[i].keepkey; //钥匙
        document.getElementById("keepKeyDate").value = record[i].keepkeydate;
        document.getElementById("OnlyUser").value = record[i].onlyuser; //独家
        document.getElementById("OnlyDate").value = record[i].onlydate;
        document.getElementById("ctyContUser").value = record[i].ctycontuser; //反签
        document.getElementById("ctyContDate").value = record[i].ctycontdate;
        document.getElementById("remark").value = record[i].remark;
        document.getElementById("isValid").value = record[i].isvalid;
        var room = document.getElementById("room");
        room.selectedIndex = record[i].room;

        var hall = document.getElementById("hall");
        hall.selectedIndex = record[i].hall;
        var restroom = document.getElementById("restroom");
        restroom.selectedIndex = record[i].restroom;
        var kitchen = document.getElementById("kitchen");
        kitchen.selectedIndex = record[i].kitchen;
        var balcony = document.getElementById("balcony");
        balcony.selectedIndex = record[i].balcony;

        var fitment = document.getElementById("fitment");
        fitment.value = record[i].fitment;
        var source = document.getElementById("source"); //来源
        source.value = record[i].source;
        var houseStyle = document.getElementById("houseStyle"); //样式
        houseStyle.value = record[i].housestyle;

        var direct = document.getElementById("direct");
        direct.value = record[i].direct;
        var propertyRight = document.getElementById("propertyRight");
        propertyRight.value = record[i].propertyright;
        var useStatus = document.getElementById("useStatus"); //使用状态
        useStatus.value = record[i].usestatus;
        var pocStatus = document.getElementById("pocStatus"); //房产证状态
        pocStatus.value = record[i].pocstatus;
//        var makename = document.getElementById("makename"); //开盘人
//        makename.value = record[i].markuser;
//        var makedept = document.getElementById("makedept"); //部门
//        makedept.value = record[i].markudept;

//        var regname = document.getElementById("regname"); //登盘人
//        regname.value = record[i].adduser;
//        var regdept = document.getElementById("regdept"); //部门
//        regdept.value = record[i].addudept;

        document.getElementById("floor").value = record[i].mark1; //楼层
        document.getElementById("leaseYear").value = record[i].mark3; //租期
        document.getElementById("mark2").value = record[i].mark2; //营业税
        var markuid = document.getElementById("markUId1"); //开盘人id
        markuid.value = record[i].markuid;
        var markuid = document.getElementById("markUser1"); //开盘人名称
        markuid.value = record[i].markuser;
        var markuid = document.getElementById("markUDeptId1"); //开盘人部门ID
        markuid.value = record[i].markudeptid;
        var markuid = document.getElementById("markUDept1"); //开盘人部门
        markuid.value = record[i].markudept;
        var markuid = document.getElementById("addUId1"); //登盘人id
        markuid.value = record[i].adduid;
        var markuid = document.getElementById("addUser1"); //登盘人
        markuid.value = record[i].adduser
        var markuid = document.getElementById("addUDept1"); //登盘人部门ID
        markuid.value = record[i].addudept;
        var markuid = document.getElementById("addUDeptId1"); //登盘人部门
        markuid.value = record[i].addudeptid
        var markuid = document.getElementById("addUBankId1"); //所属分行
        markuid.value = record[i].addubankid;

        document.getElementById("hID").value = record[i].id;//房源ID
        
        ///遍历房屋设施;
        if (usage == "1") {
            var list = record[i].happliances;
            if (list == null) {
                return;
            }
            var arr = new Array();
            arr = list.split(',');

            for (var i = 0; i < arr.length; i++) {
                var arrInputControls;
                arrInputControls = document.getElementsByName("hAppliances");
                if (arr[i] == "1") {
                    arrInputControls[i].checked = true;
                }
                else if (arr[i] == "0") {
                    arrInputControls[i].checked = false;
                }

            }
        }
    }
}

//验证电话号码以及手机号码
function chkForm(txtOTel) {
    var p1 = /^((1[0-9]{1}[0-9]{1})+\d{8})|(^(0[0-9]{2,3}\-)?([2-9][0-9]{6,7})+(\-[0-9]{1,4})?$)|(^([0-9]{3,5}\-)?([0-9]{3,8})?(\-[0-9]{3,8}))$/;

    if (txtOTel.value.substr(0, 1) == "1") {
        if (txtOTel.value.length != "11") {
            alert("号码格式不正确，请检查输入的电话号码");
            txtOTel.value = "";
            return false;
        }
    }

    if (p1.test(txtOTel.value) == false && txtOTel.value != "") {
        alert("号码格式不正确，请检查输入的电话号码");
        txtOTel.value = "";
        return false;
    }
}
//计算总价
function ComputerTotal() {
    var acreage = document.getElementById("acreage").value;
    var unitprice = document.getElementById("unitprice").value;
    var totalpric = document.getElementById("totalprice");
    var tardetype = document.getElementById("tradeType").value;
    if (tardetype == "1")
        totalpric.value = parseFloat(acreage * unitprice / 10000).toFixed(2);
    else
        totalpric.value = parseFloat(acreage * unitprice).toFixed(2);
}

function Computer() {
    var totalpric = document.getElementById("totalprice").value;
    var acreage = document.getElementById("acreage").value;
    var unitprice = document.getElementById("unitprice");
    var leaseprice = document.getElementById("leaseprice").value;
    if ((totalpric != "" && acreage != "") || (leaseprice != "" && acreage != "")) {

        var tradeType = document.getElementById("tradeType").value;
        if (tradeType == 1) {
            var sprice1 = document.getElementById("sprice").value;
            if (sprice1 == "万") {
                unitprice.value = parseFloat(totalpric * 10000 / acreage).toFixed(2);
            } else {
                unitprice.value = parseFloat(totalpric  / acreage).toFixed(2);
             }
        } else {
           var RentPrice = document.getElementById("RentPrice").value;
            if (RentPrice == "元/月") {
                unitprice.value = parseFloat(leaseprice / acreage).toFixed(2);
            } else {
               unitprice.value = parseFloat(leaseprice / acreage * 10000).toFixed(2);
             } 
        }
    }
    else {
        unitprice.value = "";
    }
}
//价格单位改变的时候，重新计算单价
function ComputerPrice() {
    var sprice1 = document.getElementById("sprice").value; //价格单位
    var totalpric = document.getElementById("totalprice").value;
    var acreage = document.getElementById("acreage").value;
    var unitprice = document.getElementById("unitprice");
    if (totalpric != "" && acreage != "") {
        if (sprice1 == "万") {
            unitprice.value = parseFloat(totalpric * 10000 / acreage).toFixed(2); //出售，单价
        } else {
            unitprice.value = parseFloat(totalpric / acreage).toFixed(2); //出租,单价
        }
    }
}
//价格单位改变的时候，重新计算单价

function CRentPrice() {
    var RentPrice = document.getElementById("RentPrice").value;
    var acreage = document.getElementById("acreage").value;
    var unitprice = document.getElementById("unitprice");
    var leaseprice = document.getElementById("leaseprice").value;
    if (leaseprice != "" && acreage != "") {
        if (RentPrice == "元/月") {
            unitprice.value = parseFloat(leaseprice / acreage).toFixed(2);
        } else {
            unitprice.value = parseFloat(leaseprice / acreage * 10000).toFixed(2);
        } 
    }
 }

//验证是否开启房号验证规则
function UsageChange() {
    var value = LexunJS.GetSelectValue("use");
    if (value != "1") {
        document.getElementById("divBackRm").style.display = "none";
        document.getElementById("divhAppliances").style.display = "none";
        document.getElementById("huxing").style.display = "none";
        document.getElementById("roomNo").readOnly = false;
        document.getElementById("floor").readOnly = false;
        

    } else {
        document.getElementById("divBackRm").style.display = "";
        document.getElementById("roomNo").readOnly = true;
        document.getElementById("divhAppliances").style.display = "";
        document.getElementById("huxing").style.display = "";
        document.getElementById("floor").readOnly = true;

    }

    //用途改变时，清空文本框内容
    document.getElementById("iEstateName").value = "";
    document.getElementById("buildName1").options.length = 0;
    document.getElementById("buildName2").options.length = 0;
    document.getElementById("buildName3").options.length = 0;
    document.getElementById("floor").value = "";
    document.getElementById("roomNo").value = "";
    document.getElementById("bname2").value = "";
    document.getElementById("bname3").value = "";
    
}

function SelectValue() {
    var tardetype = document.getElementById("tradeType").value;
    if (tardetype == "1") {
        document.getElementById("sprice1").value = "万";
        document.getElementById("sprice").value = "万";
        document.getElementById("divleaseprice").style.display = "none";
        document.getElementById("divleaseYear").style.display = "none";
        document.getElementById("divtotalprice").style.display = "";
    } else {
        document.getElementById("sprice").value = "元";
        document.getElementById("sprice1").value = "元";
        document.getElementById("divleaseprice").style.display = "";
        document.getElementById("divleaseYear").style.display = "";
        document.getElementById("divtotalprice").style.display = "none";

    }
}

//验证房间号，不能输入中文
function isChn() {
    var str = document.getElementById("roomNo");
    if (str.value != "整层") {
        var reg = /^[A-Za-z0-9-+]+$/;
        if (!reg.test(str.value) && str.value != "") {
            alert("请输入数字,字母,以及-,+，整层(-为多套连通房源用，+为双拼房源时用，请大家严格遵守)");
            str.value = "";
            str.focus();
            return false;
        }
    }

}
function isValidPositiveInteger(obj) {

    if (!LexunJS.isValidPositiveInteger(obj.value)) {

        alert("输入有误，只能为整数！");
        obj.value = "";
        return false;
    }
}

function ClearText1() {
    document.getElementById("OnlyUser").value = "";
    document.getElementById("OnlyDate").value = "";
}
function ClearText2() {
    document.getElementById("keyNo").value = "";
    document.getElementById("keepKey").value = "";
    document.getElementById("keepKeyDate").value = "";

}
function ClearText3() {
    document.getElementById("ctyContUser").value = "";
    document.getElementById("ctyContDate").value = "";
}

